package com.ice.controller;

import com.ice.pojo.Result;
import com.ice.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUploadController {

    @PostMapping("upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        //把文件的内容存储到本地磁盘上
        String originalFilename = file.getOriginalFilename(); // 获取原始文件名
        // 保证文件名是唯一的
        String filename = UUID.randomUUID().toString() + originalFilename.substring(originalFilename.lastIndexOf("."));
        //将接收的文件转存到磁盘文件中
        // file.transferTo(new File("E:\\AIODM\\big_event\\"+filename));
        String url = AliOssUtil.uploadFile(filename, file.getInputStream());

        return  Result.success(url);

    }
}
